import java.util.LinkedList;
import java.util.List;


public class Knoten {
	
	private final int id;
	private final int capacity;
	private Mash mash;
	

	private java.util.List<Knoten> nachfolger;
	private java.util.List<Knoten> vorganger;
	
	public Knoten(int id, int cap){
		this.id = id;
		this.capacity = cap;
		nachfolger = new LinkedList<Knoten>();
		vorganger = new LinkedList<Knoten>();
	}

	public void addNf(Knoten nf){
		if (nf==null)throw new IllegalArgumentException("nachfolger null");
		this.nachfolger.add(nf);
	}
	
	public void addPre(Knoten vg){
		if (vg==null)throw new IllegalArgumentException("vorganger null");
		this.vorganger.add(vg);
	}

	@Override
	public int hashCode() {
		return capacity + id;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Knoten other = (Knoten) obj;
		if (capacity != other.capacity)
			return false;
		if (id != other.id)
			return false;
		return true;
	}

	public int getId() {
		return id;
	}

	public int getCapacity() {
		return capacity;
	}

	public Mash getMash() {
		return mash;
	}

	public void setMash(Mash mash) {
		this.mash = mash;
	}

	public List<Knoten> getVorganger() {
		return vorganger;
	}
	public List<Knoten> getNachfolger(){
		return this.nachfolger;
	}
	
	public boolean pointOnMash(Mash m){
		for(Knoten k : nachfolger){
			if(m.equals(k.getMash())) return true;
		}
		return false;
	}
	
	public String toString(){
		StringBuffer sb = new StringBuffer();
		sb.append("["+ id + " " + capacity + " (");
				for (Knoten k: vorganger){
					sb.append(" " + k.getId() +" ");
				}
				
				sb.append(")]");
		return sb.toString();
	}
	
}
